using SvCore.Tcp;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Zpb;
using static ConfClient.Conf;
using static GameDefine;

public class MudRoomObjs : MonoBehaviour
{
    public ModButton ModButton;

    public Component RoomObjsContent;

    public MudRoomObjsAct MudRoomObjsAct;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void SetObjs(RoomInfo RoomInfo)
    {
        RoomObjsContent.transform.DestroyChildren();

        foreach (var item in RoomInfo.Items.Values) { NewButton(item); }
        foreach (var item in RoomInfo.Equips.Values) { NewButton(item); }
        foreach (var item in RoomInfo.Npcs.Values) { NewButton(item); }
        foreach (var item in RoomInfo.Players.Values) { NewButton(item); }
    }
    public void NewButton(ItemInfo item)
    {
        if (!ConfItem.TryGetValue(item.ConfigId, out var conf))
        {
            return;
        }
        var btn = RoomObjsContent.InstAdd(ModButton);
        btn.Text = $"{conf.Name}";
        btn.SetButtonColor(new Color(128, 128, 0));
        btn.FontSize = 24;
        btn.SetTags(RoomItem, item, conf);
        btn.SetOnClick(OnClickBtn);
    }
    public void NewButton(EquipInfo item)
    {
        if (!ConfEquip.TryGetValue(item.ConfigId, out var conf))
        {
            return;
        }
        var btn = RoomObjsContent.InstAdd(ModButton);
        btn.Text = $"{conf.Name}";
        btn.SetButtonColor(new Color(0, 255, 0));
        btn.FontSize = 24;
        btn.SetTags(RoomEquip, item, conf);
        btn.SetOnClick(OnClickBtn);
    }
    public void NewButton(NpcInfo item)
    {
        if (!ConfNpc.TryGetValue(item.ConfigId, out var conf))
        {
            return;
        }
        var btn = RoomObjsContent.InstAdd(ModButton);
        btn.Text = $"{conf.Name}";
        btn.SetButtonColor(new Color(0, 0, 160));
        btn.FontSize = 24;
        btn.SetTags(RoomNpc, item, conf);
        btn.SetOnClick(OnClickBtn);
    }
    public void NewButton(RoomInfoPlayer item)
    {
        if (item.Puid.IsSelf())
        {
            return;
        }
        var btn = RoomObjsContent.InstAdd(ModButton);
        btn.Text = $"{item.Name}";
        btn.SetButtonColor(new Color(0, 128, 255));
        btn.FontSize = 24;
        btn.SetTags(RoomPlayer, item);
        btn.SetOnClick(OnClickBtn);
    }
    public void OnClickBtn(ModButton btn)
    {
        MudRoomObjsAct.Setup(btn);
    }

    public void G2CItemGet(MyPackage pack)
    {
        pack.GetMsg(out G2CItemGet rsp);
        MudRoomObjsAct.Hide();
    }
}
